<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .search {
            width: 590px;
            height: 30px;
            border: 2px solid #4e71f2;
            outline: none;
            margin-left: 50px;
            margin-top: 50px;
            padding: 5px;
            font-size: 20px;
        }

        .box {
            width: 600px;
            /* height: 50px; */
            border: 2px solid #4e71f2;
            border-top: none;
            margin-left: 50px;
            display: none;
        }
        p{
            padding: 5px;
        }
    </style>
</head>

<body>
    <input type="text" class="search">
    <div class="box"></div>

    <script>
        let arr = ['小米手机', '华为手机', '苹果手机', '小米电视', '小米平板', '苹果12', '苹果13', '苹果手表'];

        let input = document.querySelector('.search');
        let box = document.querySelector('.box');

        // 给输入框绑定内容改变事件
        input.oninput = () => {
            // 将之前的内容给清掉
            box.innerHTML = '';

            for(let i = 0; i < arr.length; i++){

                if(arr[i].indexOf(input.value) != -1){ // 找到了
                    box.innerHTML = box.innerHTML + '<p>'+arr[i]+'</p>';
                    box.style.display = 'block';
                }
            }
        }
    </script>
</body>

</html>